'use strict'
const Joi = require('joi')
const iron = require("iron");
module.exports = {
    path: '/createUser',
    method: 'post',
    config: {
        handler: async (request, h) => {
            const pool = request.mysql.pool;
            try {
                const [rows, fields] = await pool.query('select netbar_id from base_config where id = 1')
                console.log("rows", rows)
            } catch (error) {
                console.log(error)
            }
            return  h.response({
                    name: "payload"
                })
            // let payload = request.payload;
            // payload['token'] = new Date()
            // try {
            //     let sealed = await iron.seal(payload, "123456", iron.defaults);
            //     console.log(sealed);
            //     console.log(iron.unseal(sealed, "123456", iron.defaults));
            //     return h.response({
            //         name: sealed
            //     })
            // } catch (error) {
            //     return h.response({
            //         name: payload
            //     })
            // }
        },
        description: '创建用户',
        notes: '返回成功还是失败',
        tags: ['api', 'a'],
        validate: {
            payload: {
                page: Joi.number().default(1).min(1),
                size: Joi.number().default(10).min(1),
                name: Joi.string().required().description("用户姓名"),
                age: Joi.number().required().description("年龄")
            }
        },
        plugins: {
            'hapi-swagger': {
                response: {
                    '200': {
                        description: '返回创建的用户的名字',
                        schema: Joi.object({
                            name: Joi.string().description("名字")
                        }).label("result但气温为")
                    },
                    '400': {
                        'description': 'Bad Request'
                    }
                }
            }
        }
    }
}